home *** CD-ROM | disk | FTP | other *** search
/ PC/CD Gamer UK 120 / CD Gamer Issue 120 (March 2003) (Disc 2).ISO / mods / Q2_Codered / codeRED1_0.exe / Data1.cab / NPC_astronaut.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-12-20  |  12.0 KB  |  481 lines

  1. /*
  2. ==============================================================================
  3.  
  4. Astronaut, and Redneck NPC
  5.  
  6. ==============================================================================
  7. */
  8.  
  9. #include "g_local.h"
  10. #include "npc_astronaut.h"
  11.  
  12.  
  13. static int sound_pain;
  14. static int sound_die;
  15. static int sound_idle;
  16. static int sound_talk;
  17. static int sound_talk2;
  18. static int sound_talk3;
  19. static int sound_sight;
  20. static int sound_search;
  21.  
  22. void astronaut_standstill (edict_t *self);
  23. void astronaut_fidget (edict_t *self);
  24. void astronaut_talk (edict_t *self);
  25.  
  26. void astronaut_search (edict_t *self)
  27. {
  28.     gi.sound (self, CHAN_VOICE, sound_search, 1, ATTN_NORM, 0);
  29. }
  30.  
  31. mframe_t astronaut_frames_stand [] =
  32. {
  33.     ai_stand, 0, astronaut_fidget,
  34.     ai_stand, 0, NULL,
  35.     ai_stand, 0, NULL,
  36.     ai_stand, 0, NULL,
  37.     ai_stand, 0, NULL,    
  38.     ai_stand, 0, NULL,
  39.     ai_stand, 0, NULL,
  40.     ai_stand, 0, NULL,
  41.     ai_stand, 0, NULL
  42.     
  43. };
  44. mmove_t astronaut_move_stand = {FRAME_stand01, FRAME_stand09, astronaut_frames_stand, NULL};
  45.  
  46. void astronaut_stand (edict_t *self)
  47. {
  48.     self->monsterinfo.currentmove = &astronaut_move_stand;
  49. }
  50.  
  51. mframe_t astronaut_frames_fidget [] =
  52. {
  53.     ai_stand, 0, NULL,
  54.     ai_stand, 0, NULL,
  55.     ai_stand, 0, NULL,
  56.     ai_stand, 0, NULL,
  57.     ai_stand, 0, NULL,
  58.     ai_stand, 0, NULL,    
  59.     ai_stand, 0, NULL,
  60.     ai_stand, 0, NULL,
  61.     ai_stand, 0, NULL,
  62.     ai_stand, 0, NULL,
  63.     ai_stand, 0, NULL,
  64.     ai_stand, 0, NULL,
  65.     ai_stand, 0, NULL,
  66.     ai_stand, 0, NULL,
  67.     ai_stand, 0, NULL,
  68.     ai_stand, 0, NULL,    
  69.     ai_stand, 0, NULL,
  70.     ai_stand, 0, NULL,
  71.     ai_stand, 0, NULL,
  72.     ai_stand, 0, NULL
  73.     
  74. };
  75. mmove_t astronaut_move_fidget = {FRAME_con01, FRAME_con19, astronaut_frames_fidget, astronaut_stand};
  76.  
  77. void astronaut_fidget (edict_t *self)
  78. {
  79.     if (self->spawnflags & 0) // don't want him to be at a console.
  80.         return;
  81.     if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  82.         return;
  83.     if (random() > 0.25)
  84.         return;
  85.  
  86.     self->monsterinfo.currentmove = &astronaut_move_fidget;
  87.     gi.sound (self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
  88. }
  89.  
  90. mframe_t astronaut_frames_still [] =
  91. {
  92.     ai_still, 0, NULL,
  93.     ai_still, 0, NULL,
  94.     ai_still, 0, NULL,
  95.     ai_still, 0, NULL,
  96.     ai_still, 0, NULL,
  97.     ai_still, 0, NULL,    
  98.     ai_still, 0, NULL,
  99.     ai_still, 0, NULL,
  100.     ai_still, 0, NULL,
  101.     ai_still, 0, NULL
  102.     
  103. };
  104. mmove_t astronaut_move_standstill = {FRAME_stand01, FRAME_stand09, astronaut_frames_still, astronaut_standstill};
  105.  
  106. void astronaut_standstill (edict_t *self)
  107. {
  108.     self->monsterinfo.currentmove = &astronaut_move_standstill;
  109. }
  110.  
  111. mframe_t astronaut_frames_walk [] =
  112. {
  113.     ai_run, 0.0, NULL,
  114.     ai_run, 3.3, NULL,
  115.     ai_run, 8.9, NULL,
  116.     ai_run, 10.0, NULL,
  117.     ai_run, 0.0, NULL,
  118.     ai_run, 0.0, NULL,
  119.     ai_run, 0.0, NULL,
  120.     ai_run, 3.0, NULL,
  121.     ai_run, 8.0, NULL,
  122.     ai_run, 10.0, NULL,
  123.     ai_run, 0.0, NULL,
  124.     ai_run, 0.0, NULL,
  125. };
  126. mmove_t astronaut_move_walk = {FRAME_walk01, FRAME_walk12, astronaut_frames_walk, NULL};
  127.  
  128. mframe_t astronaut_frames_walking [] =
  129. {
  130.     ai_run, 0.0, NULL,
  131.     ai_run, 3.3, NULL,
  132.     ai_run, 8.9, NULL,
  133.     ai_run, 10.0, NULL,
  134.     ai_run, 0.0, NULL,
  135.     ai_run, 0.0, NULL,
  136.     ai_run, 0.0, NULL,
  137.     ai_run, 3.0, NULL,
  138.     ai_run, 8.0, NULL,
  139.     ai_run, 10.0, NULL,
  140.     ai_run, 0.0, NULL,
  141.     ai_run, 0.0, NULL,
  142. };
  143. mmove_t astronaut_move_walking = {FRAME_walk01, FRAME_walk12, astronaut_frames_walking, NULL};
  144.  
  145. void astronaut_walk (edict_t *self)
  146. {
  147.     self->monsterinfo.currentmove = &astronaut_move_walk;
  148. }
  149.  
  150. void astronaut_walking (edict_t *self)
  151. {
  152.     self->monsterinfo.currentmove = &astronaut_move_walking;
  153. }
  154.  
  155.  
  156. mframe_t astronaut_frames_run1 [] =
  157. {
  158.     ai_run, 13, NULL,
  159.     ai_run, 25, NULL,
  160.     ai_run, 0, NULL,
  161.     ai_run, 5, NULL,
  162.     ai_run, 14, NULL,
  163.     ai_run, 24, NULL,
  164.     ai_run, 0, NULL,
  165.     ai_run, 5, NULL
  166. };
  167. mmove_t astronaut_move_run1 = {FRAME_run01, FRAME_run08, astronaut_frames_run1, NULL};
  168.  
  169. void astronaut_run (edict_t *self)
  170. {
  171.     if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  172.         self->monsterinfo.currentmove = &astronaut_move_stand;
  173.     else
  174.         self->monsterinfo.currentmove = &astronaut_move_run1;
  175. }
  176. mframe_t redneck_frames_run1 [] =
  177. {
  178.     ai_run, 0, NULL,
  179.     ai_run, 0, NULL,
  180.     ai_run, 0, NULL,
  181.     ai_run, 0, NULL,
  182.     ai_run, 0, NULL,
  183.     ai_run, 0, NULL,
  184.     ai_run, 0, NULL,
  185.     ai_run, 0, NULL,
  186.     ai_run, 0, NULL
  187. };
  188. mmove_t redneck_move_run1 = {FRAME_stand01, FRAME_stand09, redneck_frames_run1, NULL};
  189.  
  190. void redneck_run (edict_t *self)
  191. {
  192.     if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  193.         self->monsterinfo.currentmove = &astronaut_move_stand;
  194.     else
  195.         self->monsterinfo.currentmove = &redneck_move_run1;
  196. }
  197. void astronaut_run_after_talk (edict_t *self)
  198. {
  199.     if (random() < 0.8)
  200.         self->monsterinfo.currentmove = &astronaut_move_run1;
  201.     else
  202.         self->monsterinfo.currentmove = &astronaut_move_walking;
  203. }
  204.  
  205. void open_mouth(edict_t *self)
  206. {
  207.     self->s.skinnum = 1;
  208. }
  209.  
  210. void close_mouth(edict_t *self)
  211. {
  212.     self->s.skinnum = 0;
  213. }
  214.  
  215. void astronautTalk(edict_t *self)
  216. {
  217.     if (self->spawnflags & 1)
  218.         gi.sound(self, CHAN_AUTO, sound_talk2, 1, ATTN_IDLE, 0);
  219.     else
  220.         gi.sound (self, CHAN_AUTO, sound_talk, 1, ATTN_IDLE, 0);
  221. }
  222.  
  223. void astronautTalk2(edict_t *self)
  224. {
  225.     gi.sound (self, CHAN_AUTO, sound_talk3, 1, ATTN_IDLE, 0);
  226. }
  227.  
  228. mframe_t astronaut_frames_talk [] =
  229. {
  230.     ai_charge, 0, NULL,
  231.     ai_charge, 0, NULL,
  232.     ai_charge, 0, NULL,
  233.     ai_charge, 0, NULL,
  234.     ai_charge, 0, astronautTalk2,
  235.     ai_charge, 0, open_mouth,
  236.     ai_charge, 0, close_mouth,
  237.     ai_charge, 0, open_mouth,
  238.     ai_charge, 0, close_mouth,
  239.     ai_charge, 0, open_mouth,
  240.     ai_charge, 0, close_mouth,
  241.     ai_charge, 0, open_mouth,
  242.     ai_charge, 0, close_mouth,
  243.     ai_charge, 0, open_mouth,
  244.     ai_charge, 0, close_mouth,
  245.     ai_charge, 0, open_mouth,
  246.     ai_charge, 0, close_mouth,
  247.     ai_charge, 0, NULL
  248. };
  249. mmove_t astronaut_move_talk = {FRAME_talk01, FRAME_talk18, astronaut_frames_talk, astronaut_standstill};
  250.  
  251. mframe_t astronaut_frames_talkstart [] =
  252. {
  253.     ai_charge, 0, astronautTalk,
  254.     ai_charge, 0, open_mouth,
  255.     ai_charge, 0, close_mouth,
  256.     ai_charge, 0, open_mouth,
  257.     ai_charge, 0, close_mouth,
  258.     ai_charge, 0, open_mouth,
  259.     ai_charge, 0, close_mouth,
  260.     ai_charge, 0, open_mouth,
  261.     ai_charge, 0, close_mouth
  262. };
  263. mmove_t astronaut_move_talkstart = {FRAME_stand01, FRAME_stand09, astronaut_frames_talkstart, astronaut_talk};
  264.  
  265. mframe_t astronaut_frames_signal [] =
  266. {
  267.     ai_stand, 0, NULL,
  268.     ai_stand, 0, NULL,
  269.     ai_stand, 0, NULL,
  270.     ai_stand, 0, NULL,
  271.     ai_stand, 0, NULL,
  272.     ai_stand, 0, NULL,
  273.     ai_stand, 0, NULL,
  274.     ai_stand, 0, NULL,
  275.     ai_stand, 0, NULL
  276. };
  277.     
  278. mmove_t astronaut_move_signal = {FRAME_signal01, FRAME_signal09, astronaut_frames_signal, astronaut_run};
  279.  
  280. void astronaut_sight (edict_t *self, edict_t *other)
  281. {
  282.     if (self->spawnflags & 1)
  283.         self->monsterinfo.currentmove = &astronaut_move_run1;
  284.     else
  285.     {
  286.         gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
  287.         self->monsterinfo.currentmove = &astronaut_move_signal;
  288.     }
  289.     
  290. }
  291.  
  292. void astronaut_melee (edict_t *self)
  293. {
  294.     self->monsterinfo.currentmove = &astronaut_move_talkstart;
  295. }
  296.  
  297. void astronaut_talk (edict_t *self)
  298. {
  299.     if (self->spawnflags & 1)
  300.         self->monsterinfo.currentmove = &astronaut_move_standstill;
  301.     else
  302.         self->monsterinfo.currentmove = &astronaut_move_talk;
  303.         
  304. }
  305.  
  306. void astronaut_dead (edict_t *self)
  307. {
  308.     VectorSet (self->mins, -16, -16, 0);
  309.     VectorSet (self->maxs, 16, 16, 24);
  310.     self->movetype = MOVETYPE_TOSS;
  311.     self->svflags |= SVF_DEADMONSTER;
  312.     self->nextthink = 0;
  313.     gi.linkentity (self);
  314. }
  315.  
  316.  
  317. mframe_t astronaut_frames_death1 [] =
  318. {
  319.     ai_move, 0, NULL,
  320.     ai_move, 0, NULL,
  321.     ai_move, 0, NULL,
  322.     ai_move, 0, NULL,
  323.     ai_move, 0, NULL,
  324.     ai_move, 0, NULL,
  325.     ai_move, 0, NULL
  326.     
  327. };
  328. mmove_t astronaut_move_death1 = {FRAME_pain01, FRAME_pain07, astronaut_frames_death1, astronaut_dead};
  329.  
  330.  
  331. mframe_t astronaut_frames_death2 [] =
  332. {
  333.     ai_move, 0, NULL,
  334.     ai_move, 0, NULL,
  335.     ai_move, 0, NULL,
  336.     ai_move, 0, NULL,
  337.     ai_move, 0, NULL,
  338.     ai_move, 0, NULL,
  339.     ai_move, 0, NULL
  340. };
  341. mmove_t astronaut_move_death2 = {FRAME_pain01, FRAME_pain07, astronaut_frames_death2, astronaut_dead};
  342.  
  343.  
  344. void astronaut_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  345. {
  346.     int        n;
  347.  
  348.     if (self->health <= self->gib_health)
  349.     {
  350.         gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_IDLE, 0);
  351.         for (n= 0; n < 2; n++)
  352.             ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC, EF_GIB);
  353.         for (n= 0; n < 4; n++)
  354.             ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC, EF_GIB);
  355.         if (!Q_stricmp(self->classname, "npc_redneck"))
  356.             ThrowHead (self, "models/npc/redneck_dead/tris.md2", damage, GIB_ORGANIC, EF_GIB);
  357.         else
  358.             ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC, EF_GIB);
  359.         self->deadflag = DEAD_DEAD;
  360.         return;
  361.     }
  362.  
  363.     if (self->deadflag == DEAD_DEAD)
  364.         return;
  365.  
  366.     gi.sound (self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
  367.     self->deadflag = DEAD_DEAD;
  368.     self->takedamage = DAMAGE_YES;
  369.  
  370.     if (damage >= 50)
  371.         self->monsterinfo.currentmove = &astronaut_move_death1;
  372.     else
  373.         self->monsterinfo.currentmove = &astronaut_move_death2;
  374. }
  375.  
  376.  
  377. /*QUAKED monster_astronaut (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
  378. */
  379. void SP_npc_astronaut (edict_t *self)
  380. {
  381.     if (deathmatch->value)
  382.     {
  383.         G_FreeEdict (self);
  384.         return;
  385.     }
  386.     
  387.     // pre-caches
  388.     sound_pain  = gi.soundindex ("astronaut/pain.wav");
  389.     sound_die   = gi.soundindex ("astronaut/death.wav");
  390.     sound_idle  = gi.soundindex ("astronaut/breathe.wav");
  391.     sound_talk = gi.soundindex ("astronaut/talk.wav");
  392.     sound_talk2 = gi.soundindex ("astronaut/talk2.wav");
  393.     sound_talk3 = gi.soundindex ("astronaut/talk3.wav");
  394.     sound_search = gi.soundindex ("astronaut/yell.wav");
  395.     sound_sight = gi.soundindex ("astronaut/yell.wav");
  396.  
  397.     self->s.modelindex = gi.modelindex("models/npc/astronaut/tris.md2");
  398.     self->s.modelindex2 = gi.modelindex ("models/npc/helmet/tris.md2");
  399.  
  400.     VectorSet (self->mins, -16, -16, 0);
  401.     VectorSet (self->maxs, 16, 16, 56);
  402.     self->movetype = MOVETYPE_STEP;
  403.     self->solid = SOLID_BBOX;
  404.  
  405.     self->classname = "npc_astronaut";
  406.       
  407.     self->health = 150;
  408.     self->gib_health = 40;
  409.     self->mass = 150;
  410.  
  411.     self->pain = NULL;
  412.     self->die = astronaut_die;
  413.     self->monsterinfo.stand = astronaut_stand;
  414.     self->monsterinfo.walk = astronaut_walk;
  415.     self->monsterinfo.run = astronaut_run;
  416.     self->monsterinfo.dodge = NULL;
  417.     self->monsterinfo.attack = NULL;
  418.     self->monsterinfo.melee = astronaut_melee;
  419.     self->monsterinfo.sight = astronaut_sight;
  420.     self->monsterinfo.search = astronaut_search;
  421.  
  422.     self->monsterinfo.currentmove = &astronaut_move_stand;
  423.     self->monsterinfo.scale = MODEL_SCALE;
  424.     self->monsterinfo.aiflags = AI_NPC;
  425.  
  426.     gi.linkentity (self);
  427.  
  428.     walkmonster_start (self);
  429. }
  430. void SP_npc_redneck (edict_t *self)
  431. {
  432.     if (deathmatch->value)
  433.     {
  434.         G_FreeEdict (self);
  435.         return;
  436.     }
  437.     
  438.     // pre-caches
  439.     sound_pain  = gi.soundindex ("astronaut/pain.wav");
  440.     sound_die   = gi.soundindex ("astronaut/death.wav");
  441.     sound_idle  = gi.soundindex ("astronaut/breathe.wav");
  442.     sound_talk = gi.soundindex ("redneck/talk.wav");
  443.     sound_talk2 = gi.soundindex ("redneck/talk2.wav");
  444.     sound_talk3 = gi.soundindex ("redneck/talk3.wav");
  445.     sound_search = gi.soundindex ("astronaut/yell.wav");
  446.     sound_sight = gi.soundindex ("astronaut/yell.wav");
  447.  
  448.     self->s.modelindex = gi.modelindex("models/npc/redneck/tris.md2");
  449.  
  450.     VectorSet (self->mins, -16, -16, 0);
  451.     VectorSet (self->maxs, 16, 16, 56);
  452.     self->movetype = MOVETYPE_STEP;
  453.     self->solid = SOLID_BBOX;
  454.  
  455.     self->classname = "npc_redneck";
  456.       
  457.     self->max_health = 150;
  458.     self->health = self->max_health;
  459.     self->gib_health = 40;
  460.     self->mass = 150;
  461.  
  462.     self->pain = NULL;
  463.     self->die = astronaut_die;
  464.     self->monsterinfo.stand = astronaut_stand;
  465.     self->monsterinfo.walk = astronaut_stand;
  466.     self->monsterinfo.run = redneck_run;
  467.     self->monsterinfo.dodge = NULL;
  468.     self->monsterinfo.attack = NULL;
  469.     self->monsterinfo.melee = astronaut_talk;
  470.     self->monsterinfo.sight = NULL;
  471.     self->monsterinfo.search = astronaut_search;
  472.  
  473.     self->monsterinfo.currentmove = &astronaut_move_stand;
  474.     self->monsterinfo.scale = MODEL_SCALE;
  475.     self->monsterinfo.aiflags = AI_NPC;
  476.  
  477.     gi.linkentity (self);
  478.  
  479.     walkmonster_start (self);
  480. }
  481.